import 'package:flutter/material.dart';

class GOverlayUtils {
  static OverlayEntry? loadingOverlayEntry;
  static void showLoading(BuildContext context, {String? message}) {
    Size size = MediaQuery.of(context).size;
    if (loadingOverlayEntry != null) {
      loadingOverlayEntry?.remove();
    }
    loadingOverlayEntry = OverlayEntry(
      builder: (_) {
        return AbsorbPointer(
          child: Container(
            decoration: const BoxDecoration(color: Colors.black12),
            width: size.width,
            height: size.height,
            child: Center(
                child: Text(
              message ?? "加载中",
              style: const TextStyle(
                  color: Colors.white,
                  fontSize: 18,
                  fontStyle: FontStyle.normal),
            )),
          ),
        );
      },
    );
    Overlay.of(context)?.insert(loadingOverlayEntry!);
  }

  static void endLoading() {
    loadingOverlayEntry?.remove();
    loadingOverlayEntry = null;
  }
}
